Skip to content

feat(core): pass client logger to request handlers#2170

Open
aBurmeseDev wants to merge 6 commits into
smithy-lang:mainfrom
aBurmeseDev:feat/pass-client-logger-to-request-handler
Open

feat(core): pass client logger to request handlers#2170
aBurmeseDev wants to merge 6 commits into
smithy-lang:mainfrom
aBurmeseDev:feat/pass-client-logger-to-request-handler

Conversation

@aBurmeseDev

@aBurmeseDev aBurmeseDev commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available:
aws/aws-sdk-js-v3#6130
JS-7027

Description of changes:

Pass the client's logger to the HTTP request handler via updateHttpClientConfig so it can log connection-level diagnostics (warnings, debug info, etc).

Testing

  • unit tests for logger injection in getHttpHandlerExtensionConfig
  • unit tests for NodeHttpHandler.updateHttpClientConfig nullish
  • unit tests for UndiciHttpHandler.updateHttpClientConfig

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aBurmeseDev
aBurmeseDev requested a review from a team as a code owner July 21, 2026 08:23
aBurmeseDev and others added 2 commits July 21, 2026 01:29
TypeScript strict mode cannot narrow `value` from the full
`NodeHttpHandlerOptions[typeof key]` union when branching on
`key === "logger"`. Add an explicit cast to fix the build:types
target in CI.
@aBurmeseDev
aBurmeseDev marked this pull request as draft July 23, 2026 17:46
@aBurmeseDev aBurmeseDev changed the title feat(node-http-handler): pass client logger to request handlers feat(core): pass client logger to request handlers Jul 24, 2026
@aBurmeseDev
aBurmeseDev marked this pull request as ready for review July 24, 2026 06:23
export const getHttpHandlerExtensionConfiguration = <HandlerConfig extends object = {}>(
runtimeConfig: HttpHandlerExtensionConfigType<HandlerConfig>
) => {
runtimeConfig.httpHandler?.updateHttpClientConfig("logger" as keyof HandlerConfig, (runtimeConfig as any).logger);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a truthy check?

Suggested change
runtimeConfig.httpHandler?.updateHttpClientConfig("logger" as keyof HandlerConfig, (runtimeConfig as any).logger);
if ((runtimeConfig as any).logger) {
runtimeConfig.httpHandler?.updateHttpClientConfig("logger" as keyof HandlerConfig, (runtimeConfig as any).logger);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the truthy check so we don't call updateHttpClientConfig with undefined/null

});

it("updates config", async () => {
it("does not overwrite an existing logger via updateHttpClientConfig", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should updateHttpClientConfig skip overriding existing logger?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateHttpClientConfig should always overwrites, removed the nullish assignment.

export const getHttpHandlerExtensionConfiguration = <HandlerConfig extends object = {}>(
runtimeConfig: HttpHandlerExtensionConfigType<HandlerConfig>
) => {
runtimeConfig.httpHandler?.updateHttpClientConfig("logger" as keyof HandlerConfig, (runtimeConfig as any).logger);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method call must be checked too. ?.

try requiring HandlerConfig extends { logger?: Logger } instead of casting a literal to something it isn't.

This should be backwards compatible.

https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgDIHsDmnrIN4BQyxyANlgBQB0NcUmAzgFzICuIA1iOgO4gDaAXQCULAG7pgAEwDcBAL4ECoSLEQoAShACOrCAzAAJOCCmloAHgDCAPnxESrAA5S4kChwgBPFp6-oYZCsAGmQxOFIWdi5eEFEwyVkFJRh2BDBgdBBkBAjSAFUXNwhrZAgAD0hTBmQKPDIsHCgAfhYMbFx5YRsKAAsTM2gWLV19IwHzKGsbYXsSZH7TSapnV3cAInIOqHXQkFZSUmE5RQIELIMFiaHkEb0DYyXLPHk7AF5kfcPkOBqTLzkZzyhTWED61ygxyAA

interface Logger {
    log(...args: unknown[]): void;
}

interface RequestHandler<C> {
    update(key: keyof C, val: unknown): void;
}

function callUpdate<C extends ({ logger?: Logger })>(handler: RequestHandler<C>) {
    handler.update("logger", null);
}

const handler: RequestHandler<{}> = null as any;

callUpdate(handler);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added ?. on the method and Logger import with the constraint (HandlerConfig extends { logger?: Logger }).
Also wrapped in a truthy check, so we skip the call entirely when there's no logger.

this.configProvider = this.configProvider.then((config) => {
if (key === "logger") {
return { ...config, logger: config.logger ?? (value as NodeHttpHandlerOptions["logger"]) };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes it impossible to update the logger once it's set

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the nullish assignment. updateHttpClientConfig now does a plain overwrite for all keys including logger.

@kuhe kuhe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at additional requestHandler implementations in AWS SDK JS.

at this time, handlers which resolve config asynchronously don't offer a way to query whether there is a higher priority logger set on the requestHandler at requestHandler initialization.

We need a plan to account for this problem.

@aBurmeseDev
aBurmeseDev requested a review from kuhe July 24, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants